home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / mxlist.zip / DMX_LIST.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-04  |  10KB  |  357 lines

  1. Unit DMX_LIST;
  2.  
  3. {$V-,I- }
  4.  
  5. (*
  6.   All the "object-orientedness" is handled internally within this unit.
  7.   There are two global procedure to be called by the main program.
  8.   Each procedure uses a different object to do the work, and one is a
  9.   descendant of the other.
  10.  
  11.   The text-files are temporarily stored on the heap while it is displayed.
  12.   They are freed from the heap when the procedure is finished.
  13.  
  14.   These procedures use GETMEM and FREEMEM for heap manipulations.
  15.  *)
  16.  
  17. interface
  18.  
  19.  
  20. uses   Dos, Crt, DMX2, DMX_wind;
  21.  
  22.  
  23.  
  24.   procedure ViewTextWindow (Filename : pathstr;  Bor,Txt : word);
  25.  
  26.       { This procedure views a text-file in the currently defined window }
  27.  
  28.  
  29.   procedure ViewHelpWindow (Filename : pathstr;  Help : char;
  30.                             Y1,X1,Y2,X2, Bor,Txt : word);
  31.  
  32.       { This procedure differs from ViewTextWindow in two ways:
  33.  
  34.          1) The window size is determined by the parameters given.
  35.  
  36.          2) Only the lines of text which begin with the character equal
  37.             to the HELP variable are displayed.  This allows more than
  38.             one help-screen in each help-file.
  39.  
  40.        }
  41.  
  42.  
  43.  
  44.   { ─────────────────────────────────────────────────────────────────────── }
  45.  
  46.  
  47. implementation
  48.  
  49.  
  50. const  cr          =  #13;
  51.        Esc         =  #27;
  52.        F1          =  ';';
  53.  
  54.        lastline    =  999;  { This is the maximum number of text-lines that
  55.                               can be displayed.  It should be increased if
  56.                               you need to use larger files.
  57.                              }
  58.  
  59.  
  60. type   tableptr    = ^tabletype;
  61.        tabletype   =  array [0..lastline] of ^string; {pointers to text-lines}
  62.  
  63.        TextViewer  =  object (DMXviewer)
  64.                         ImageSize     : longint;  { accumulated data size }
  65.                         table         : tableptr;
  66.  
  67.                         procedure Loader (Filename  : pathstr);
  68.                                   virtual;
  69.                         procedure RedoRuler (Gauge, Line : word);
  70.                                   virtual;
  71.                         function  DataAt (recnum : longint) : pointer;
  72.                                   virtual;
  73.                         destructor Done;
  74.                       end;
  75.  
  76.  
  77.        HelpViewer  =  object (TextViewer)
  78.                         helpcode      : char;
  79.                         procedure Loader (Filename  : pathstr);
  80.                                   virtual;
  81.                       end;
  82.  
  83.  
  84.  
  85. var    ReadWindow  :  TextViewer;
  86.        HelpWindow  :  HelpViewer;
  87.        marker      :  byte;  { just a place to point to }
  88.        Key,ext     :  char;
  89.  
  90.  
  91.   { ─────────────────────────────────────────────────────────────────────── }
  92.  
  93.  
  94. procedure TextViewer.RedoRuler (Gauge, Line : word);
  95. { virtual method called after adjusting the upper or lower border }
  96.  
  97. { You may have noticed that the line above the editing space will be doubled
  98.   when it is no longer possible to scroll upwards.  The lower border behaves
  99.   in a likewise fashion.
  100.   This virtual procedure is normally unused, but is needed here to "clean-up"
  101.   the edges of each border --which are just outside the window space.
  102.   This procedure was not documented in the unregistered version, because it
  103.   is rarely needed.
  104.  
  105.   GAUGE determines whether the ruler is be single or double width; and
  106.   LINE determines which ruler is being displayed.
  107.  
  108.   This procedure is only called when the GAUGE changes }
  109.  
  110.  
  111. var  L,R : char;
  112. begin
  113.   Line := Line + hi (WindMin);
  114.   If Line <= succ (hi (WindMin)) then
  115.     begin
  116.     If Gauge = 1 then
  117.       begin
  118.       L := '╓';  R := '╖';  { ruler is single width }
  119.       end
  120.      else
  121.       begin
  122.       L := '╔';  R := '╗';  { ruler is double width }
  123.       end;
  124.     end
  125.    else
  126.     begin
  127.     If Gauge = 1 then
  128.       begin
  129.       L := '╙';  R := '╜';  { ruler is single width }
  130.       Screen ('[more '#25']', Line, lo (WindMax) - 7, bordercolor);
  131.       end
  132.      else
  133.       begin
  134.       L := '╚';  R := '╝';  { ruler is double width }
  135.       end;
  136.     end;
  137.   Screen (L, Line, lo (WindMin),     bordercolor);
  138.   Screen (R, Line, lo (WindMax) + 2, bordercolor);
  139. end;
  140.  
  141.  
  142.   { ─────────────────────────────────────────────────────────────────────── }
  143.  
  144.  
  145. function  TextViewer.DataAt (recnum : longint) : pointer;
  146. { this virtual method pretends to retrieve the next record }
  147. const  nix : char = #0;  { simulates a nul string }
  148. begin
  149.   If recnum >= recordlimit then
  150.     DataAt := addr (nix)  { point to a nul string }
  151.    else
  152.     DataAt := Table^[recnum]
  153. end;
  154.  
  155.  
  156.   { ─────────────────────────────────────────────────────────────────────── }
  157.  
  158.  
  159. procedure TextViewer.Loader (Filename : pathstr);
  160. var  AStr   : string;
  161.      Cover  : text;
  162. begin
  163.   Table       := nil;
  164.   ImageSize   :=  0;
  165.  
  166.   GetMem (Table, sizeof (tabletype));
  167.   recordlimit :=  0;
  168.   AStr        := '';
  169.  
  170.   Assign (Cover, Filename);
  171.   Reset (Cover);
  172.   If IoResult <> 0 then
  173.     begin
  174.     GetMem (Table^[0], 21);  { string length + 1 }
  175.     Table^[0]^  :=  'File not found.';
  176.  
  177.     recordlimit := 1;
  178.     ImageSize   := ImageSize + recordsize;
  179.     end
  180.    else
  181.     begin
  182.     Repeat
  183.       readln (Cover, AStr);
  184.       If length (AStr) > succ (recordsize) then
  185.         AStr [0] := chr (succ (recordsize));
  186.       GetMem (Table^[recordlimit], length (AStr) + 1);
  187.       Move (AStr, Table^[recordlimit]^, length (AStr) + 1);
  188.       Inc (recordlimit);
  189.       ImageSize := ImageSize + recordsize;
  190.     Until (IoResult <> 0) or Eof (Cover) or (recordlimit = lastline);
  191.     Close (Cover);
  192.     end;
  193.  
  194.   OpenBuffer (marker, ImageSize);
  195.  
  196. end;  { TextViewer.Loader }
  197.  
  198.  
  199.   { ─────────────────────────────────────────────────────────────────────── }
  200.  
  201.  
  202. procedure HelpViewer.Loader (Filename : pathstr);
  203. var  AStr   : string;
  204.      Cover  : text;
  205. begin
  206.   Table       := nil;
  207.   ImageSize   :=  0;
  208.  
  209.   GetMem (Table, sizeof (tabletype));
  210.   recordlimit :=  0;
  211.   AStr        := '';
  212.  
  213.   Assign (Cover, Filename);
  214.   Reset (Cover);
  215.   If IoResult <> 0 then
  216.     begin
  217.     AStr        :=  'File not found.';
  218.     GetMem (Table^[0], length (AStr) + 1);
  219.     Move (AStr, Table^[0]^, length (AStr) + 1);
  220.     recordlimit := 1;
  221.     ImageSize   := ImageSize + recordsize;
  222.     end
  223.    else
  224.     begin
  225.     Repeat
  226.       readln (Cover, AStr);
  227.       If (length (AStr) > 0)
  228.         and
  229.          (AStr [1] = helpcode)
  230.        then
  231.         begin
  232.         Delete (AStr, 1,1);
  233.         If length (AStr) > succ (recordsize) then
  234.           AStr [0] := chr (succ (recordsize));
  235.         GetMem (Table^[recordlimit], length (AStr) + 1);
  236.         Move (AStr, Table^[recordlimit]^, length (AStr) + 1);
  237.         Inc (recordlimit);
  238.         ImageSize := ImageSize + recordsize;
  239.         end;
  240.     Until (IoResult <> 0) or Eof (Cover) or (recordlimit = lastline);
  241.     Close (Cover);
  242.     end;
  243.  
  244.   If recordlimit = 0 then
  245.     begin
  246.     AStr        :=  'Help is not available for this item.';
  247.     GetMem (Table^[0], length (AStr) + 1);
  248.     Move (AStr, Table^[0]^, length (AStr) + 1);
  249.     recordlimit := 1;
  250.     ImageSize   := ImageSize + recordsize;
  251.     end;
  252.  
  253.   OpenBuffer (marker, ImageSize);
  254.  
  255. end;  { HelpViewer.Loader }
  256.  
  257.  
  258.   { ─────────────────────────────────────────────────────────────────────── }
  259.  
  260.  
  261. destructor TextViewer.Done;
  262. var  i : word;
  263. begin
  264.   If Table <> nil then
  265.     begin
  266.     If recordlimit > 0 then
  267.       For i := 0 to pred (recordlimit) do
  268.         FreeMem (Table^[i], length (Table^[i]^) + 1);
  269.     FreeMem (Table, sizeof (Table^));
  270.     recordlimit := 0;
  271.     end;
  272. end;
  273.  
  274.  
  275.   { ─────────────────────────────────────────────────────────────────────── }
  276.  
  277.  
  278. procedure ViewTextWindow (Filename : pathstr;  Bor,Txt : word);
  279. type  win   =  record  X,Y : byte;  end;
  280. const Rfmt  :  string [80] = ' _______________________________________________________________________________';
  281. var   TA    :  word;
  282.       FMode :  word;
  283. begin
  284.   FMode    := FileMode;
  285.   FileMode :=  0;  { just in case the file is marked ReadOnly }
  286.   TA       := TextAttr;
  287.   TextAttr := Txt;
  288.  
  289.   ClrScr;
  290.   MkBorder (succ (hi (WindMin)), succ (lo (WindMin)),
  291.             succ (hi (WindMax)), succ (lo (WindMax)), Bor);
  292.   Inc (win (WindMin).X);
  293.   Dec (win (WindMax).X);  { make the window thinner to avoid border }
  294.  
  295.   Rfmt [0] := chr (succ (lo (WindMax) - lo (WindMin)));
  296.   ReadWindow.Init ('', Rfmt, 1,1, Bor,Txt,Txt);
  297.  
  298.   ReadWindow.Loader (Filename);
  299.  
  300.   ReadWindow.EditData (marker, Key,ext, [Esc],[]);
  301.  
  302.   ReadWindow.Done;
  303.  
  304.   Dec (win (WindMin).X);
  305.   Inc (win (WindMax).X);  { fix window's width }
  306.  
  307.   FileMode := FMode;
  308.   TextAttr := TA;
  309. end;  { ViewTextWindow }
  310.  
  311.  
  312.   { ─────────────────────────────────────────────────────────────────────── }
  313.  
  314.  
  315. procedure ViewHelpWindow (Filename : pathstr;   Help : char;
  316.                           Y1,X1,Y2,X2, Bor,Txt : word);
  317. type  win   =  record  X,Y : byte;  end;
  318. const Rfmt  :  string [80] = ' _______________________________________________________________________________';
  319. var   FMode :  word;
  320. begin
  321.   SaveWindow;  { saves screen, color, and cursor positions }
  322.   Window (X1,Y1,X2,Y2);
  323.  
  324.   HelpWindow.helpcode := Help;
  325.   FMode    := FileMode;
  326.   FileMode :=  0;  { just in case the file is marked ReadOnly }
  327.   TextAttr := Txt;
  328.  
  329.   ClrScr;
  330.   MkBorder (succ (hi (WindMin)), succ (lo (WindMin)),
  331.             succ (hi (WindMax)), succ (lo (WindMax)), Bor);
  332.   Inc (win (WindMin).X);
  333.   Dec (win (WindMax).X);  { make the window thinner to avoid border }
  334.  
  335.   Rfmt [0] := chr (succ (lo (WindMax) - lo (WindMin)));
  336.   HelpWindow.Init ('', Rfmt, 1,1, Bor,Txt,Txt);
  337.  
  338.   HelpWindow.Loader (Filename);
  339.  
  340.   HelpWindow.EditData (marker, Key,ext, [#13,Esc],[F1]);
  341.  
  342.   HelpWindow.Done;
  343.  
  344.   Dec (win (WindMin).X);
  345.   Inc (win (WindMax).X);  { fix window's width }
  346.  
  347.   FileMode := FMode;
  348.  
  349.   RestoreWindow;
  350. end;  { ViewHelpWindow }
  351.  
  352.  
  353.   { ─────────────────────────────────────────────────────────────────────── }
  354.  
  355.  
  356. End.
  357.